import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * list的遍历
 */
public class ListDemo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("first");
        list.add("second");
        list.add("third");
        list.add("fourth");

        //for
        System.out.println("--------------------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        //迭代器
        System.out.println("--------------------");
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
        //foreach
        System.out.println("--------------------");
        for(String each:list){
            System.out.println(each);
        }
        //lambda
        System.out.println("--------------------");
        list.forEach(s -> System.out.println(s));
    }
}
